//
//  BaseTabBarViewController.swift
//  Exchange
//
//  Created by rui on 2018/4/18.
//  Copyright © 2018年 common. All rights reserved.
//

import UIKit

class BaseTabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        configViewControllers()
        // Do any additional setup after loading the view.
    }
    
    private func configViewControllers() {
        
        let market = creatOneViewController(title: kText("首页"), image: ThemeManager.ThemeImageKeys.tabHomeNormal, selectImage: ThemeManager.ThemeImageKeys.tabHomeSelected, rootVC: MarketViewController())
        
        let currencyExchangede = creatOneViewController(title: kText("币币交易"), image: ThemeManager.ThemeImageKeys.tabExchangeNormal, selectImage: ThemeManager.ThemeImageKeys.tabExchangeSelected, rootVC: CurrencyExchangeViewController())
        
        let currencyTrade = creatOneViewController(title: kText("法币交易"), image: ThemeManager.ThemeImageKeys.tabTradeNormal, selectImage: ThemeManager.ThemeImageKeys.tabTradeSelected, rootVC: CurrencyTradeViewController())
        
//        let leveragedTrade = creatOneViewController(title: kText("杠杆交易"), image: ThemeManager.ThemeImageKeys.tabLeveragedNoraml, selectImage: ThemeManager.ThemeImageKeys.tabLeveragedSelected, rootVC: LeveragedTradeViewController())
        
        let mine = creatOneViewController(title: kText("我的"), image: ThemeManager.ThemeImageKeys.tabMineNormal, selectImage: ThemeManager.ThemeImageKeys.tabMineSelected, rootVC: MineViewController())
        
        viewControllers = [market,currencyExchangede,currencyTrade,mine]
        
        self.tabBar.themeBarTintColor = ThemeManager.ThemeColorKeys.tabbarBackground
    }
    
    private func creatOneViewController(title: String, image: String, selectImage: String, rootVC: UIViewController) -> UINavigationController {
        let nav = NavigationController(rootViewController: rootVC)
        let item = UITabBarItem()
        item.title = title
        item.themeImage = image
        item.themeSelectedImage = selectImage
        item.themeSetTitleColor(ThemeManager.ThemeColorKeys.tabbarTitle, for: .normal)
        item.themeSetTitleColor(ThemeManager.ThemeColorKeys.text1, for: .selected)
        nav.tabBarItem = item
        
//        nav.tabBarItem.setTitleTextAttributes([NSAttributedStringKey.foregroundColor:UIColor.black], for: .normal)
//        nav.tabBarItem.setTitleTextAttributes([NSAttributedStringKey.foregroundColor : UIColor.yellow], for: .selected)
        
        rootVC.title = title
        return nav
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        
    }
}


extension BaseTabBarViewController {
    
    override var shouldAutorotate: Bool {
        get {
            return true
        }
    }
    
    override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        get {
            return .portrait
        }
    }
    
    override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
        get {
            return .portrait
        }
    }
}
